<template>
  <div class="edit_form">
    <!-- 编辑页 -->
    <edu-form :title="textMap[dialogStatus]" @ok="createData()" @cancel="handelCancel">
      <a-form-model ref="veStuChangeDataForm" :rules="veStuChangeRules" :model="veStuChangeVo" labelAlign="right">
        <div class="detail_title">原学籍基本信息</div>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="姓名" class="ytop" prop="name">
              {{ veBaseStudentVo.xm }}
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="学号" class="ytop" prop="code">
              {{ veBaseStudentVo.xh }}
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="所属专业部" prop="xz">
              {{ veBaseStudentVo.falText }}
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="所属专业" prop="xz">
              {{ veBaseStudentVo.specText }}
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="所属班级" prop="xz">
              {{ veBaseStudentVo.bjText }}
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="异动类别" prop="ydlbm" required>
              <edu-data v-model="veStuChangeVo.ydlbm" stype="select" code="ydlbm" />
            </a-form-model-item>
          </a-col>
        </a-row>
        <template>
          <div class="detail_title mt" v-if="veStuChangeVo.ydlbm == 3 || veStuChangeVo.ydlbm == 4 || veStuChangeVo.ydlbm == 6">异动信息</div>
          <a-form-model-item class="ytop" v-if="veStuChangeVo.ydlbm == 3" label="专业去向" prop="boxZybmbj">
            <boxZybmbj ref="boxZybmbj" nianji nianjiToBj></boxZybmbj>
          </a-form-model-item>

          <a-form-model-item class="ytop" v-if="veStuChangeVo.ydlbm == 4" label="留级去向" prop="boxZybmbj2">
            <boxZybmbj ref="boxZybmbj2" :ofalId="veBaseStudentVo.falId" :ospecId="veBaseStudentVo.specId" nianji njbj nianjiToBj></boxZybmbj>
          </a-form-model-item>

          <a-form-model-item class="ytop" v-if="veStuChangeVo.ydlbm == 6" label="异动去向" prop="ydqxxm">
            <a-input v-model="veStuChangeVo.ydqxxm" :maxLength="50" placeholder="请输入异动去向" />
          </a-form-model-item>
        </template>

        <div class="detail_title mt">其他信息</div>

        <a-form-model-item label="异动原因" class="ytop" prop="ydMsg" required>
          <a-textarea v-model="veStuChangeVo.ydMsg" :maxLength="65535" placeholder="请输入异动说明" :rows="4" />
        </a-form-model-item>
        <a-form-model-item label="异动说明" class="ytop" prop="ydsm" required>
          <a-textarea v-model="veStuChangeVo.ydsm" :maxLength="65535" placeholder="请输入异动说明" :rows="4" />
        </a-form-model-item>
      </a-form-model>
    </edu-form>
  </div>
</template>

<script>
import veStuChangeApi from '@/module/stu/base/api/veStuChangeApi';
import veBaseStudentApi from '@/module/stu/base/api/veBaseStudentApi';
import boxZybmbj from '@/components/boxZybmbj';

export default {
  components: { boxZybmbj },
  data() {
    let validateBoxZybmbj = (rule, value, callback) => {
      const data = this.$refs.boxZybmbj.getCheck();
      if (data) {
        callback(new Error(data));
      } else {
        callback();
      }
    };
    let validateBoxZybmbj2 = (rule, value, callback) => {
      const data = this.$refs.boxZybmbj2.getCheck();
      if (data) {
        callback(new Error(data));
      } else {
        callback();
      }
    };
    const data = {
      veStuChangeVo: this.resetveStuChangeVo(),
      veBaseStudentVo: {},
      veBaseStudentInfoVo: {},
      textMap: {
        update: '编辑学籍异动',
        create: '编辑学籍异动'
      },
      dialogStatus: 'create',
      veStuChangeRules: {
        boxZybmbj: [{ validator: validateBoxZybmbj, trigger: 'change', required: true }],
        boxZybmbj2: [{ validator: validateBoxZybmbj2, trigger: 'change', required: true }]
      }
    };
    return data;
  },
  mounted() {},
  methods: {
    /**
     * @msg: 重置数据
     */
    resetveStuChangeVo() {
      return {
        code: '', // 学号
        name: '', // 姓名
        stuId: '', // 学生id
        ydlbm: '', // 异动类别码;1=>'退学',2=>'休学',3=>'转专业',4=>'留级',5=>'转入',6=>'转出',
        ydDate: '', // 异动日期
        ydMsg: '', // 异动原因
        spDate: '', // 审批日期
        spwh: '', // 审批文号
        jbrgh: '', // 经办人工号
        ydlyxxm: '', // 异动来源学校码
        ydqxxm: '', // 异动去向学校码
        ydsm: '', // 异动说明
        ofalId: '', //
        ospecId: '', // 原专业码
        objId: '', // 原班号
        ogradeId: '', // 原年级
        falId: '', // 院系
        specId: '', // 专业码
        bjId: '', // 班级
        gradeId: '', // 年级
        isRecover: '', // 异动恢复状态;1已恢复
        recoverUserId: '', // 异动恢复操作人id
        recoverTime: '' // 异动恢复时间
      };
    },
    /**
     * @msg: 初始化修改
     */
    doChange(row) {
      veBaseStudentApi.get(row.id).then(res => {
        this.veBaseStudentVo = res.result.stu;
        this.veBaseStudentInfoVo = res.result.stuInfo;
      });
      this.viewType = 'update';
      this.$nextTick(() => {
        this.$refs.veStuChangeDataForm.clearValidate();
      });
    },
    /**
     * @msg: 编辑页取消
     */
    handelCancel() {
      this.$emit('onCancel');
    },
    /**
     * @msg: 获取提交的数据 新增和 修改复用
     */
    getSubData(isUpdate, callback) {
      const tempData = Object.assign({}, this.veStuChangeVo);
      if (veStuChangeVo.ydlbm == 4) {
        this.$refs.boxZybmbj.getSetValue(tempData, () => {
          callback(tempData);
        });
      } else if (veStuChangeVo.ydlbm == 3) {
        this.$refs.boxZybmbj2.getSetValue(
          tempData,
          () => {
            tempData.stuId = this.veBaseStudentVo.id;
            tempData.code = this.veBaseStudentVo.code;
            tempData.name = this.veBaseStudentVo.name;
            tempData.ydDate = this.$date.format('YYYY-MM-DD');
            callback(tempData);
          },
          { fal: false, zy: false }
        );
      }
    },
    /**
     * @msg: 调用Api创建数据
     */
    createData() {
      this.$refs.veStuChangeDataForm.validate(valid => {
        if (valid) {
          this.getSubData(false, subData => {
            if (subData == null) {
              return;
            }
            veStuChangeApi.add(subData).then(res => {
              this.$notification.success({
                message: '数据新增成功',
                description: '新增了一条数据'
              });
              this.$emit('onOk');
            });
          });
        }
      });
    }
  }
};
</script>
<style lang="less" scoped></style>
